package io.renren.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.entity.RefundEntity;
import io.renren.service.RefundService;
import io.renren.utils.PageUtils;
import io.renren.utils.Query;
import io.renren.utils.R;


/**
 * 交退款
 * 
 * @author zhangheng
 * @email zh_123shmily@163.com
 * @date 2017-08-05 18:20:49
 */
@RestController
@RequestMapping("refund")
public class RefundController extends AbstractController{
	@Autowired
	private RefundService refundService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("refund:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<RefundEntity> refundList = refundService.queryList(query);
		int total = refundService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(refundList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("refund:info")
	public R info(@PathVariable("id") Integer id){
		RefundEntity refund = refundService.queryObject(id);
		
		return R.ok().put("refund", refund);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("refund:save")
	public R save(@RequestBody RefundEntity refund){
		refundService.save(refund);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("refund:update")
	public R update(@RequestBody RefundEntity refund){
		refundService.update(refund);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("refund:delete")
	public R delete(@RequestBody Integer[] ids){
		refundService.deleteBatch(ids);
		
		return R.ok();
	}

	public R payment(@RequestBody JSONObject jsonObject){

		return R.ok();
	}

	public R getInComeInfo(@RequestBody JSONObject jsonObject){

		return R.ok();
	}

	@RequestMapping("/getRefundInfoByDSId/{id}")
	@RequiresPermissions("refund:info")
	public R getRefundInfoByDSId(@PathVariable("id") Integer id) {
		HashMap<String, Object> map = refundService.getRefundInfoByDSId(id+"");

		return R.ok().put("map", map);
	}

	@RequestMapping("/saveRefund")
	@RequiresPermissions("refund:save")
	public R saveRefund(@RequestBody JSONObject jsonObject){
		jsonObject.put("user",getUser());
		refundService.saveRefund(jsonObject);
		return R.ok();
	}

	@RequestMapping("/saveRefundContract")
	@RequiresPermissions("refund:save")
	public R saveRefundContract(@RequestBody JSONObject jsonObject){
		jsonObject.put("user",getUser());
		refundService.saveRefundContract(jsonObject);
		return R.ok();
	}
}
